package com.mapfinal.server.web;

import java.awt.image.BufferedImage;
import java.util.List;

import com.mapfinal.platform.bufferedimage.BufferedImageJFinalRender;
import com.mapfinal.server.MapfinalServer;
import com.mapfinal.server.ServerMap;
import com.mapfinal.server.layer.ServerLayer;
import com.mapfinal.server.service.wms.Wms;

public class IndexController extends MapfinalServerController {

	public void index() {
	}
	
	public void simple() {
		Wms wms = new Wms(this);
		if(!wms.isOk()) {
			renderJson(WebResult.json(WebResultConsts.INVALID_PARAM));
			return;
		}
		//获取layer
		List<ServerLayer> serverLayers = MapfinalServer.me().getLayers(wms.getLayers());
		if(serverLayers.size() < 1) {
			renderJson(WebResult.json(WebResultConsts.FAILED, "layers not find", null));
			return;
		}
		//新建map
		ServerMap map = new ServerMap(wms.getWidth(), wms.getHeight(), BufferedImage.TYPE_INT_ARGB);
		map.view().fitBounds(wms.toEnvelope());
		//图层加入到map中
		for(int i=0; i<serverLayers.size(); i++ ) {
			map.addLayer(serverLayers.get(i).getLayer());
		}
		//新建输出瓦片
        //ServerImage imageTile = new ServerImage(256, 256, BufferedImage.TYPE_INT_ARGB);
        //map.draw(imageTile);
		BufferedImage image = map.draw();
        //返回图片
        render(new BufferedImageJFinalRender(image, wms.getImageFormat()));
	}
}
